home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************
- * *
- * When debugging, set the project type to application, *
- * and add the ANSI project. *
- * *
- * When all your bugs are out, 'undef' DEBUG, set the project *
- * type to Code Resource, with type = ACMD, name = <the name *
- * of the function>, file type to 'AEXT', and the purgeable *
- * flag set to true. *
- * *
- * Also, you need to remove the ANSI project from the ACMD *
- * project and replace it with the ANSI-A4 project if you use *
- * any functions in ANSI, such as strlen. *
- * *
- * If you are not using THINK C, I'm not quite sure what you *
- * should do. :-) *
- * *
- * Change History: *
- * ================================================== *
- * 8/6/90 Fixed bug w/ last lines. *
- * *
- ******************************************************************/
-
-
- #undef DEBUG
-
-
- #include <stdio.h>
- #include <string.h>
-
- #define STAR '*'
- #define CR '\r'
- #ifdef DEBUG
- #define TABSIZE 8 /* default printf size */
- #else DEBUG
- #define TABSIZE 4 /* default ALPHA size */
- #endif DEBUG
-
- char *left(char *);
- char *right(char *);
- char *repeatChar(char *, char, long);
-
-
- char *
- #ifdef DEBUG
- dummy(inStr)
- #else DEBUG
- main(inStr)
- #endif DEBUG
- char *inStr;
- {
- long lines, longest, len, i, j;
- char *ptr, *mptr, c, *lineBeg;
- char *mem;
-
- lines = 1;
- longest = 0;
-
- for (ptr = inStr,len = 0; *ptr; ptr++)
- {
- switch (*ptr)
- {
- case CR:
- case '\0':
- lines++;
- if (len > longest) longest = len;
- len = 0;
- break;
- case '\t':
- len = (((len + 2) / TABSIZE) + 1) * TABSIZE - 2;
- break;
- default:
- len++;
- break;
- }
- }
- if (len > longest) longest = len;
- if (*(ptr - 1) == '\r')
- {
- *(ptr - 1) = 0;
- lines--;
- }
-
- if (!(mem = NewPtr((lines + 4) * (longest + 5) + 2)))
- {
- SysBeep(2);
- return(inStr);
- }
-
- ptr = mem;
- *ptr++ = '/';
- ptr = repeatChar(ptr,STAR,longest + 3);
- *ptr++ = CR;
- ptr = left(ptr);
- ptr = repeatChar(ptr, ' ', longest);
- ptr = right(ptr);
- for (i = 0, mptr = inStr; i < lines; i++, mptr++)
- {
- ptr = left(ptr);
- lineBeg = mptr;
- for (len = 0; ((c = *mptr) != CR) && c; *ptr++ = *mptr++)
- {
- switch (c = *mptr)
- {
- case CR:
- case '\0':
- len = 0;
- break;
- case '\t':
- len = (((len + 2) / TABSIZE) + 1) * TABSIZE - 2;
- break;
- default:
- len++;
- }
- }
- ptr = repeatChar(ptr, ' ', longest - len);
- ptr = right(ptr);
- }
- ptr = left(ptr);
- ptr = repeatChar(ptr, ' ', longest);
- ptr = right(ptr);
- ptr = repeatChar(ptr, STAR, longest + 3);
- *ptr++ = '/';
- *ptr++ = '\r';
- *ptr = '\0';
-
- /* Must free w/ 'DisposPtr' and allocate w/ 'NewPtr' */
- DisposPtr(inStr);
- return(mem);
- }
-
- char * left(ptr)
- char *ptr;
- {
- *ptr++ = STAR;
- *ptr++ = ' ';
- return(ptr);
- }
-
-
- char * right(ptr)
- char *ptr;
- {
- *ptr++ = ' ';
- *ptr++ = STAR;
- *ptr++ = CR;
- return(ptr);
- }
-
-
- char * repeatChar(ptr, c, num)
- char *ptr, c;
- long num;
- {
- long i;
-
- for (i = 0; i < num; i++)
- *ptr++ = c;
- return(ptr);
- }
-
- #ifdef DEBUG
-
- char * ConvertRtoN(char *theStr);
-
- char * ConvertRtoN(theStr)
- char *theStr;
- {
- char *currentChar;
-
- for (currentChar = theStr;*currentChar != 0; currentChar++)
- if (*currentChar == '\r')
- *currentChar = '\n';
- }
-
- main()
- {
- char *str3 = "this is nice";
- char *str4 = "nice\r> 1234 fstatus;\reasy\r";
- char *str2 = "Nice\r\tand\reasy\r";
- char *str = "(define fixLexYyC\r set matchWords 0\r set forward 1\r";
-
- char *ret, *in;
-
- in = NewPtr(strlen(str) + 1);
- strcpy(in, str);
-
- ret = dummy(in);
-
- ConvertRtoN(ret); /* Convert '\r' to '\n' so we can see them in a printf */
- ConvertRtoN(str);
-
- printf("The original is:\n\n%s", str);
- printf("\n----\n\nThe result is:\n\n%s", ret);
-
- }
- #endif DEBUG
-